package com.blb.community_admin.controller;

import com.blb.community_admin.Annotation.Log;
import com.blb.community_admin.entity.ZyOwnerRoomRecord;
import com.blb.community_admin.service.ZyOwnerRoomRecordService;
import com.blb.community_admin.util.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

@Api
@RestController
public class ZyOwnerRoomRecordController {

    @Autowired
    private ZyOwnerRoomRecordService zyOwnerRoomRecordService;

    @Log(module = "业主审核记录", operationType = 1, requestMethod = "POST")
    @ApiOperation("添加记录")
    @PostMapping("/record")
    public ResponseResult<String> addRecord(@RequestBody ZyOwnerRoomRecord zyOwnerRoomRecord){
        zyOwnerRoomRecord.setCreateTime(LocalDateTime.now());
        zyOwnerRoomRecordService.save(zyOwnerRoomRecord);
        return ResponseResult.ok("添加完成");
    }

    @ApiOperation("审核记录")
    @PostMapping("/record/{id}")
    public ResponseResult<List<ZyOwnerRoomRecord>> getRoomRecord(@PathVariable Long id){
        List<ZyOwnerRoomRecord> records = zyOwnerRoomRecordService.getRecords(id);
        System.out.println(records);
        records.forEach(a->{
            System.out.println(a);
        });
        return ResponseResult.ok(records);
    }
}
